package com.dzh.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig  implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("list");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                // addPathPatterns 用于添加拦截规则
                // excludePathPatterns 用于排除拦截
                //注：因为疏忽下方的index.html前面未加/,转发多次-->StackOverflowError
                .addPathPatterns("/**").excludePathPatterns("/index.html","/","/login","/user/login",
                "/assets/**","/assets/brand/**","/assets/dist/css/**","/assets/dist/js/**");
    }

}
